//
//  PageViewSummaryCell.swift
//  
//
//  Created by Ralf on 6/12/15.
//
//

import UIKit

class PageViewSummaryCell: TableViewCell
{
    var summaryLabel:         UILabel!
    var presetLabel:          UILabel!
    //预定方式
    var nationalExpressLabel: UILabel!

    override func awakeFromNib()
    {
        super.awakeFromNib()
        initSummary()
        initPreset()
        initNationalExpress()
        // Initialization code
    }

    override func setSelected(selected: Bool, animated: Bool)
    {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

    func setData(data: NSMutableDictionary)
    {
        let advertising = data["article"] as! [String:AnyObject]
        setSummary(advertising["summary"] as! String)
        setPreset(advertising["preset"] as! String)
//        let nationalExpress = Bool(advertising["nationalExpress"] as! Int)
//        setNationalExpress(nationalExpress)
//        summaryLabel.text = advertising["summary"] as? String
//        cityLabel.text = advertising["city"] as? String
//        var startTime = advertising["startTime"] as? String
//
//        startTime = startTime?.toDate(formatString: "yyyy-MM-dd'T'HH:mm:ssZ")?.toLongDateString()
//        var endTime = advertising["endTime"] as? String
//        endTime = endTime?.toDate(formatString: "yyyy-MM-dd'T'HH:mm:ssZ")?.toLongDateString()
//
//        startTimeLabel.text = startTime! + " 至 " + endTime!
    }

    func setSummary(summary: String)
    {
        summaryLabel.text = summary
    }

    func setPreset(preset: String)
    {
        presetLabel.text = preset
    }

    func setNationalExpress(nationalExpress: Bool)
    {
        if nationalExpress
        {
            nationalExpressLabel.hidden = false
        }
        else
        {
            nationalExpressLabel.hidden = true
        }
    }

    func initSummary()
    {
        if summaryLabel == nil
        {
            let frame = CGRect(x: 10, y: 5, width: UIScreen.mainScreen().bounds.size.width - 10, height: 20)
            summaryLabel = UILabel(frame: frame)
            summaryLabel.font = UIFont.systemFontOfSize(14)
            self.addSubview(summaryLabel)
        }
    }

    func initPreset()
    {
        if presetLabel == nil
        {
            let frame = CGRect(x: 10, y: 25, width: UIScreen.mainScreen().bounds.size.width / 2 - 5, height: 20)
            presetLabel = UILabel(frame: frame)
            presetLabel.font = UIFont.systemFontOfSize(14)
            self.addSubview(presetLabel)
        }
    }

    func initNationalExpress()
    {
        if nationalExpressLabel == nil
        {
            let frame = CGRect(x: UIScreen.mainScreen().bounds.size.width / 2, y: 25, width: UIScreen.mainScreen().bounds.size.width / 2 - 10, height: 20)
            nationalExpressLabel = UILabel(frame: frame)
            nationalExpressLabel.textAlignment = .Right
            nationalExpressLabel.font = UIFont.systemFontOfSize(14)
            self.addSubview(nationalExpressLabel)
        }
    }
}
